//
// Created by ziya on 22-8-20.
//

#ifndef ZIYA_MINITHREAD_C_MINITHREAD_H
#define ZIYA_MINITHREAD_C_MINITHREAD_H

#include "../common.h"

#define TASK_SIZE 32

typedef void* (*coroutine_fun_t)(void*);

typedef enum coroutine_state {
    COROUTINE_INIT,     // 初始化
    COROUTINE_RUNNING,  // 执行
    COROUTINE_READY,    // 就绪
    COROUTINE_BLOCKED,  // 阻塞
    COROUTINE_SLEEPING, // 睡眠
    COROUTINE_WAITING,  // 等待
    COROUTINE_DIED,     // 死亡
} coroutine_state_t;

typedef struct coroutine {
    coroutine_state_t   state;
    coroutine_fun_t     fun;
    char*               esp3;
    char                name[16];   // 协程名
    int                 zid;        // 协程ID
    int                 counter;    // 运行时间片
    int                 priority;   // 调度优先级，越大越先调度，获得的时间片越多
} coroutine_t;

uint coroutine_create(OUT uint* pzid, coroutine_fun_t entry, char* name, int priority);

void coroutine_exit();

#endif //ZIYA_MINITHREAD_C_MINITHREAD_H
